<?php

namespace App\Services\Common;

use App\Models\Notice\Notice;
use Overtrue\Pinyin\Pinyin;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;

class Common
{

    public static function getCommon(string $key)
    {

        return 'aaaa';
    }

    /**
     * 消息管理，系通发送消息
     * @param $manger_id 用户id
     * @param $order_number 订单号
     * @param $notice_type 消息类型
     * @return true
     */
    public static function sendnotice($cpid, $manger_id, $order_number, $contents)
    {
        $data = [
            'cpid' => $cpid,
            'manger_id' => $manger_id,
            'order_number' => $order_number,
            'contents' => $contents,
            'status' => config('constants.notice.unread'),
            'create_at' => time(),
        ];
        Notice::create($data);
        return true;
    }


    public static function getPinyin($hanzi){
        $pinyin = new Pinyin();

        return  $pinyin->permalink($hanzi,'');
    }


    public static function MangerInfo(Request $request){
        $token = $request->header('token');
        $utype=$request->header('utype');

        $mangerinfo = Redis::get($token);

        $mangerinfo = $mangerinfo ? json_decode($mangerinfo, true) : [];



        if (isset($mangerinfo['id']) && isset($mangerinfo['cpid'])) {
            $tokenbyid = Redis::get('manger_user_tokenbyid_' . $mangerinfo['id']);
            if ($token!=$tokenbyid) {
                return ;
            }
        } else {
            return ;
        }

        if(!in_array($utype,$mangerinfo['utypes'])){
            return ;
        }


        return ['id' => $mangerinfo['id'], 'cpid' => $mangerinfo['cpid'], 'utype' => $utype, 'code_no' => $mangerinfo['code_no'], 'pid' => $mangerinfo['pid'], 'realname' => $mangerinfo['realname'], 'mobile' => $mangerinfo['mobile'],'cpd_id'=>$mangerinfo['cpd_id'],'sys_dpm_id'=>$mangerinfo['sys_dpm_id']];


    }

}
